package test

import grails.test.*

import org.apache.commons.lang.time.DateUtils

class UserTests extends GrailsUnitTestCase {

	void testFindAllActive() {
		mockDomain(User)
		
		// given
		new User(login: "login1", password: "pass1", email: "", birthDate: new Date(), active: false).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: new Date(), active: false).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: new Date(), active: true).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: new Date(), active: true).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: new Date(), active: true).save()
		
		// when
		def result = User.findAllActive()
		
		// then
		assert result.size == 3
	}
	
    void testFindChildren() {
		mockDomain(User)
		
		// given
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -16)).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -17)).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -18)).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -19)).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -20)).save()
		
		// when
		def result = User.findChildren()
		
		// then
		assert result.size == 2
		
    }

    void testFindAdults() {
		mockDomain(User)
		
		// given
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -16)).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -17)).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -18)).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -19)).save()
		new User(login: "login1", password: "pass1", email: "", birthDate: DateUtils.addYears(new Date(), -20)).save()
		
		// when
		def result = User.findAdults()
		
		// then
		assert result.size == 3
		
    }
}
